<?php

use Phinx\Db\Adapter\PdoAdapter;
use Phinx\Migration\AbstractMigration;

class CreateDocumentRelationTable extends AbstractMigration
{
    /**
     * up change
     */
    public function up()
    {
        $table = $this
            ->table("document_relation", [
                'id' => false,
                'primary_key' => ['id'],
                'engine' => 'InnoDB',
                'collation' => 'utf8mb4_general_ci',
                'comment' => '文档关联表'
            ])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键'])
            ->addColumn("relation_id", PdoAdapter::PHINX_TYPE_STRING, [
                "limit" => "80",
                "null" => false,
                "default" => "",
                "comment" => "关联id",
            ])
            ->addColumn("relation_type", "enum", [
                "values" => "default,task_requirements,task_standard",
                "null" => false,
                "default" => "default",
                "comment" => "关联类型",
            ])
            ->addColumn("post_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                "signed" => false,
                'comment' => "文档id"
            ])
            ->addColumn("tenant_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                'comment' => "租户id"
            ])
            ->addColumn("project_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                'comment' => "项目id"
            ])
            ->addColumn("entity_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                "signed" => false,
                'comment' => "实体id"
            ])
            ->addColumn("step_category_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                "signed" => false,
                'comment' => "工序分类id"
            ])
            ->addColumn("project_template_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                'comment' => "项目模板id"
            ])
            ->addColumn("step_workflow_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                'comment' => "工序流id"
            ])
            ->addColumn("step_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                'comment' => "工序id"
            ])
            ->addColumn("item_id", "integer", [
                'limit' => 11,
                'null' => false,
                'default' => 0,
                "signed" => false,
                'comment' => "文档项目id"
            ])
            ->addColumn("item_catalog_id", PdoAdapter::PHINX_TYPE_STRING, [
                "limit" => "60",
                "null" => false,
                "default" => "",
                "comment" => "文档目录id",
            ])
            ->addColumn("param", 'json', ['null' => true, 'comment' => '额外参数'])
            ->addColumn('created', 'integer', [
                'signed' => false,
                'default' => 0,
                'limit' => 11,
                'comment' => '创建时间'
            ])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者']);

        $table->save();


    }

    /**
     * down change
     */
    public function down()
    {
        $this->table("document_relation")->drop()->save();
    }
}
